package com.dqhl.community.adapter;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.activity.DistributionDetailActivity;
import com.dqhl.community.activity.EvaluateActivity;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.model.OrderRecord;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.Dlog;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LIENLIN on 2016/8/31.
 */
public class OrderLvAdapter extends BaseMyAdapter {

    private int mResId;
    private Button mBtnPingjia;
    private List<OrderRecord> orderRecordList;

    public OrderLvAdapter(Context context, int mResId, List<OrderRecord> orderRecordList) {
        super(context);
        this.mResId = mResId;
        this.orderRecordList = orderRecordList;
    }

    @Override
    public int getCount() {
        Log.d("order", "orderRecordList.size()=" + orderRecordList.size());
        return orderRecordList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(mResId, viewGroup, false);
        }
//
        final TextView tv_status = ViewHolder.get(view, R.id.tv_status);
//        ListView mLvGoods = ViewHolder.get(view, R.id.lv_goods_order);
        TextView tv_number_money = ViewHolder.get(view, R.id.tv_total_money);
        final OrderRecord orderRecord = orderRecordList.get(i);
        //显示订单状态
        switch (orderRecord.getStatus()) {
            case "1":
                tv_status.setText("订单已生成");
                break;
            case "2":
                tv_status.setText("已取消");
                break;
            case "3":
                tv_status.setText("付款成功");
                break;
            case "4":
                tv_status.setText("货到付款");
                break;
            case "5":
                tv_status.setText("已发货");
                break;
            case "6":
                tv_status.setText("配送中");
                break;
            case "7":
                tv_status.setText("货到付款已支付");
                break;
            case "8":
                tv_status.setText("买家签收");
                break;
            case "9":
                tv_status.setText("他人代收");
                break;
            case "10":
                tv_status.setText("签收异常");
                break;
            case "11":
                tv_status.setText("退货");
                break;
            case "12":
                tv_status.setText("退款");
                break;
            case "13":
                tv_status.setText("订单完成");
                break;
        }
        //显示订单商品
        final ArrayList<OrderRecord.Good> goodsList = orderRecord.getGoods();
//        mLvGoods.setAdapter(new BaseMyAdapter(context) {
//            @Override
//            public int getCount() {
//                Log.d("order", "goodsList.size()=" + goodsList.toString());
//                return goodsList.size();
//            }
//
//            @Override
//            public Object getItem(int i) {
//                return orderRecord.getId();//返回订单id
//            }
//
//            @Override
//            public long getItemId(int i) {
//                return 0;
//            }
//
//            @Override
//            public View getView(int i, View view, ViewGroup viewGroup) {
//
//                View v = inflater.inflate(R.layout.order_goods_item, viewGroup, false);
//                ImageView iv_pic = ViewHolder.get(v, R.id.iv_pic);
//                TextView tv_name = ViewHolder.get(v, R.id.tv_name);
//                TextView tv_price = ViewHolder.get(v, R.id.tv_price);
//                TextView mTvPingJia = ViewHolder.get(v, R.id.tv_pingjia);//评价按钮
//
//                final OrderRecord.Good good = goodsList.get(i);
//                x.image().bind(iv_pic, Config.Api.base_img_url + good.getGoods_pic());
//                tv_name.setText(good.getName());
//                tv_price.setText("￥" + good.getPrice_one());
//
//                switch (orderRecord.getStatus()) {
//                    case "8":
//                    case "9":
//                    case "11":
//                    case "12":
//                    case "13":
//                        mTvPingJia.setVisibility(View.VISIBLE);
//                        mTvPingJia.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View view) {
//                                Bundle bundle = new Bundle();
//                                bundle.putString("pic", good.getGoods_pic());
//                                bundle.putString("name", good.getName());
//                                bundle.putString("price", good.getPrice_one());
//                                overlay(EvaluateActivity.class, bundle);
//                            }
//                        });
//                        break;
//
//                }
//                return v;
//            }
//        });
        //内listview点击
//        mLvGoods.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
////                String order_id = orderRecordList.get(0).getId();
//
//                String order_id = (String) adapterView.getItemAtPosition(i);
//                String goods_ids = goodsList.get(i).getGoods_id();
//                Dlog.e("int i " + i + "  goods_ids  " + goods_ids);
//                Bundle bundle = new Bundle();
//                bundle.putString("order_id", order_id);
//
//                overlay(DistributionDetailActivity.class, bundle);
//            }
//        });

        String string = "共" + orderRecord.getNumber() + "件商品实付金额：￥" + orderRecord.getTotal();
        tv_number_money.setText(string);
        return view;
    }
}
